<?php

class Solution
{

    /**
     * @param String $s
     * @return Integer
     */
    function lengthOfLastWord($s)
    {
        $arr = preg_split("/[\s]+/", $s);
        $index = count($arr) - 1;
        $lastWord = $arr[$index];
        $len = strlen($lastWord);
        if ($len == 0) {
            $lastWord = $arr[$index - 1];
            $len = strlen($lastWord);
        }
        return $len;
    }
}
